<<BACK

(Remi/David)

library(sf)
library(marmap)
library(raster)
library(tidyverse)
library(ggplot2)

IMAGINE!

Let’s imagine that you are interested in a species in a given area and wish to know as much as possible about it. But, you can’t go out in the field because funding is running short. What you do have, however, is a certain knowledge of the tools that are available to you and you are wondering how far they can take you. Let’s find out.

Defining species and area of interest

    # Let's select Atlantic cod as our species of interest
    sp <- 'Gadus morhua'

    # And the gulf of St. Lawrence as our study area
    #define the corners
    latmax <- 52.01312
    latmin <- 45.52399
    lonmax <- -55.73636
    lonmin <- -71.06333

Describe your species

Fishbase

We’ll start with a description of the species. First, let’s see what fishbase has to offer.

    # install.packages('rfishbase')
    descr <- rfishbase::species(sp)
    ecol <- rfishbase::ecology(sp)
    ecol <- cbind(colnames(ecol), t(ecol))
    rownames(ecol) <- NULL

    kable(ecol, col.names = c('Descriptors', 'Attributes'))
Descriptors Attributes
autoctr 33
sciname Gadus morhua
StockCode 79
EcologyRefNo 1371
HabitatsRef 1371
Neritic -1
SupraLittoralZone 0
Saltmarshes 0
LittoralZone 0
TidePools 0
Intertidal -1
SubLittoral 0
Caves 0
Oceanic -1
Epipelagic 0
Mesopelagic 0
Bathypelagic 0
Abyssopelagic 0
Hadopelagic 0
Estuaries -1
Mangroves 0
MarshesSwamps 0
CaveAnchialine 0
Stream 0
Lakes 0
Cave 0
Cave2 0
Herbivory2 mainly animals (troph. 2.8 and up)
HerbivoryRef 5743
FeedingType hunting macrofauna (predator)
FeedingTypeRef 5743
DietTroph 4.09
DietSeTroph 0.179
DietTLu 4.34
DietseTLu 0.72
DietRemark Troph of adults from 7 studies.
DietRef 26813
FoodTroph 4.29
FoodSeTroph 1
FoodRemark Trophic level estimated from a number of food items using a randomized resampling routine.
FoodRef NA
AddRems Opportunistic predator that forages mainly at dawn and dusk (Refs. 1371, 46189). Larvae feed mainly on zooplankton while juveniles prey predominantly on benthic crustaceans; adults feed mainly on zoobenthos and fish (Refs. 5743, 9604, 26813) including juvenile cod. Fish prey becomes more common in the diet with increasing body size (Refs. 1371, 89387). Adults may cover large distances during the feeding period (Ref. 89387).
Young cod are also pre yed upon by different fish species and octopus. Adult cod are prey items of top predators like sharks, rays, whales, dolphins, seals, and sea birds (Refs. 9023, 9581, 26954, 43651, 45735).
In the Baltic it grows up to 5 kg weight in 7-8 years; in the North Sea it reaches 8 kg in the same time span . Natural mortality for adults of both stocks is assumed to be around M=0.2, resulting in a mean adult life expectancy and mean duration of the reproductive phase of 5 years (Ref. 88171).
Parasites of the speci es include protozoans (trypanosome), myxosporidians, monogeneid, trematodes, cestodes, nematodes, acanthocephalan, hirudinid and copepods (Ref. 5951).
AssociationRef NA
Parasitism 0
Solitary 0
Symbiosis 0
Symphorism 0
Commensalism 0
Mutualism 0
Epiphytic 0
Schooling -1
SchoolingFrequency sometimes
SchoolingLifestage juveniles and adults
Shoaling 0
ShoalingFrequency NA
ShoalingLifestage NA
SchoolShoalRef 1371
AssociationsWith NA
AssociationsRemarks Generally considered a demersal fish although its habitat may become pelagic under certain hydrogrphic conditions, when feeding or spawning. There is some evidence that cod leave the bottom and school pelagically to spawn in preferred temperatures when bottom tempetatures are unsuitable. Gregarious during the day, forming compact schools that swim between 30-80 m above the bottom, and scatter at night (Ref. 1371). Schooling behavior may be adaptive for feeding. Reproductive behavior during spawning involves the circling of a female often by only one male per spawning bout (Ref. 86779).
OutsideHost 0
OHRemarks NA
InsideHost 0
IHRemarks NA
SubstrateRef NA
Benthic 0
Sessile 0
Mobile 0
Demersal 0
Endofauna 0
Pelagic 0
Megabenthos 0
Macrobenthos 0
Meiobenthos 0
SoftBottom -1
Sand 0
Coarse 0
Fine 0
Level 0
Sloping 0
Silt 0
Mud 0
Ooze 0
Detritus 0
Organic 0
HardBottom -1
Rocky -1
Rubble 0
SpecialHabitatRef NA
Macrophyte 0
BedsBivalve 0
BedsRock 0
SeaGrassBeds -1
BedsOthers 0
CoralReefs 0
ReefExclusive 0
DropOffs 0
ReefFlats 0
Lagoons 0
Burrows 0
Tunnels 0
Crevices 0
Vents 0
Seamounts 0
DeepWaterCorals 0
Vegetation 0
Leaves 0
Stems 0
Roots 0
Driftwood 0
OInverterbrates 0
OIRemarks NA
Verterbrates 0
VRemarks NA
Pilings 0
BoatHulls 0
Corals 0
SoftCorals 0
OnPolyp 0
BetweenPolyps 0
HardCorals 0
OnExoskeleton 0
InterstitialSpaces 0
Entered 2
Dateentered 1991-10-17T00:00:00.000Z
Modified 2374
Datemodified 2014-02-06T00:00:00.000Z
Expert NA
Datechecked NA
TS NA
SpecCode 69

Taxize

We can also get it’s taxonomy rather easily.

    # install.packages('taxize')
    taxo <- taxize::classification(sp, db = 'worms', verbose = FALSE)
    kable(taxo[[1]])
name rank id
Animalia Kingdom 2
Chordata Phylum 1821
Vertebrata Subphylum 146419
Gnathostomata Superclass 1828
Pisces Superclass 11676
Actinopterygii Class 10194
Gadiformes Order 10313
Gadidae Family 125469
Gadus Genus 125732
Gadus morhua Species 126436

GloBI

How about extracting all known preys and predators of the species of interest?

    # install.packages('rglobi')
    prey <- rglobi::get_prey_of(sp)$target_taxon_name
    pred <- rglobi::get_predators_of(sp)$target_taxon_name
    prey
##  [1] "Neocalanus tonsus"             "Pseudocalanus elongatus"      
##  [3] "Arctica islandica"             "Gastrosaccus spinifer"        
##  [5] "Diastylis rathkei"             "Buccinum undatum"             
##  [7] "Corystes cassivelanus"         "Eledone cirrhosa"             
##  [9] "Gonatus fabricii"              "Bathypolypus arcticus"        
## [11] "Rossia moelleri"               "Bathypolypus bairdii"         
## [13] "Todarodes sagittatus"          "Cancer pagurus"               
## [15] "Rossia macrosoma"              "Pandalus borealis"            
## [17] "Pandalus montagui"             "Lithodes maja"                
## [19] "Hyas coarctatus"               "Crangon allmanni"             
## [21] "Galathea strigosa"             "Ophiopholis aculeata"         
## [23] "Natatolana borealis"           "Atelecyclus rotundatus"       
## [25] "Crangon crangon"               "Carcinus maenas"              
## [27] "Mya arenaria"                  "Pagurus bernhardus"           
## [29] "Ophiothrix fragilis"           "Psammechinus miliaris"        
## [31] "Trisopterus luscus"            "Callionymus lyra"             
## [33] "Actinopterygii"                "Gadiformes"                   
## [35] "Gobiidae"                      "Eutrigla gurnardus"           
## [37] "Trachurus trachurus"           "Hippoglossoides platessoides" 
## [39] "Scomber scombrus"              "Lepidorhombus whiffiagonis"   
## [41] "Trisopterus esmarkii"          "Sardina pilchardus"           
## [43] "Trisopterus minutus"           "Enchelyopus cimbrius"         
## [45] "Buglossidium luteum"           "Microchirus variegatus"       
## [47] "Merlangius merlangus"          "Actinopterygii"               
## [49] "Ammodytes tobianus"            "Clupea harengus"              
## [51] "Mallotus villosus"             "Lethenteron camtschaticum"    
## [53] "Lumpenus lampretaeformis"      "Sprattus sprattus"            
## [55] "Pomatoschistus minutus"        "Zoarces viviparus"            
## [57] "Gadus morhua"                  "Ammodytes marinus"            
## [59] "Buenia jeffreysii"             "Lophius piscatorius"          
## [61] "Sebastes viviparus"            "Microstomus kitt"             
## [63] "Agonus cataphractus"           "Solea solea"                  
## [65] "Merluccius merluccius"         "Micromesistius poutassou"     
## [67] "Salmo salar"                   "Myxine glutinosa"             
## [69] "Glyptocephalus cynoglossus"    "Scophthalmus rhombus"         
## [71] "Pleuronectes platessa"         "Pollachius virens"            
## [73] "Scophthalmus maximus"          "Zeugopterus punctatus"        
## [75] "Melanogrammus aeglefinus"      "Phrynorhombus norvegicus"     
## [77] "Squalus acanthias"             "Merluccius bilinearis"        
## [79] "Zoarces americanus"            "Pseudopleuronectes americanus"
## [81] "Scophthalmus aquosus"          "Ammodytes dubius"             
## [83] "Limanda limanda"               "Myoxocephalus scorpius"       
## [85] "Scyliorhinus canicula"
    pred
##  [1] "Larus"                        "Thalasseus sandvicensis"     
##  [3] "Phalacrocorax carbo"          "Phoca vitulina"              
##  [5] "Sprattus sprattus"            "Clupea harengus"             
##  [7] "Scomber scombrus"             "no name"                     
##  [9] "Gadus morhua"                 "Thunnus thynnus"             
## [11] "Petromyzon marinus"           "Pollachius virens"           
## [13] "Molva molva"                  "Squalus acanthias"           
## [15] "Hippoglossoides platessoides" "Pomatomus saltatrix"         
## [17] "Myxine glutinosa"             "Lophius piscatorius"         
## [19] "Eutrigla gurnardus"           "Hippoglossus hippoglossus"   
## [21] "Amblyraja radiata"            "Anarhichas lupus"            
## [23] "Reinhardtius hippoglossoides" "Sebastes"                    
## [25] "Sebastes mentella"            "Xiphias gladius"             
## [27] "Merlangius merlangus"

Make your search spatially explicit

Get data from OBIS

OBIS is the Ocean Biogeographic Information System and their vision is: “To be the most comprehensive gateway to the world’s ocean biodiversity and biogeographic data and information required to address pressing coastal and world ocean concerns.”

We can get access to their HUGE database through the excellent robis package by ropensci (unsurprisingly, they also have other great open science R packages, from which this whole section is highly inspired)

st_as_text(bb$geometry)
OBIS <- robis::occurrence(scientificname = sp, geometry=st_as_text(bb$geometry), startdate = as.Date("2010-01-01"), enddate = as.Date("2017-01-01"))
write.csv(OBIS,'obis.csv',row.names = FALSE)

Visualize data

We can easily visualize the data…

OBIS <- read.csv("obis.csv")
plot(OBIS[,c("decimalLongitude", "decimalLatitude")])

… but the aesthetics could be much better!

Plot your study site

Define site map limits

Let’s start by defining a bounding box for your study site:

#create a matrix
bbmat <- cbind(
            c(lonmin,lonmax,lonmax,lonmin,lonmin),
            c(latmin,latmin,latmax,latmax,latmin)
        )
# make the matrix a 'simple features' polygon
bbsf <- st_polygon(list(bbmat))
# and let's give it information about the projection:
bbsfc <- st_sfc(bbsf,crs="+proj=longlat +datum=WGS84")
# finally, let's make it a simple features data.frame
bb <- st_sf(name="Study Site",geometry=bbsfc)
str(bb)
## Classes 'sf' and 'data.frame':   1 obs. of  2 variables:
##  $ name    : chr "Study Site"
##  $ geometry:sfc_POLYGON of length 1; first list element: List of 1
##   ..$ : num [1:5, 1:2] -71.1 -55.7 -55.7 -71.1 -71.1 ...
##   ..- attr(*, "class")= chr  "XY" "POLYGON" "sfg"
##  - attr(*, "sf_column")= chr "geometry"
##  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA
##   ..- attr(*, "names")= chr "name"
# plot it!
ggplot(bb) + geom_sf()

Add a basemap!

There are many ways to add a basemap in R

marmap package

bathymetry <- getNOAA.bathy(lonmin,lonmax,latmin,latmax,resolution=1,keep=TRUE)
## File already exists ; loading 'marmap_coord_-71.06333;45.52399;-55.73636;52.01312_res_1.csv'
plot.bathy(bathymetry,image=T,drawlabels=TRUE)

blues <- colorRampPalette(c("darkblue", "lightblue1"))
greys <- colorRampPalette(c(grey(0.4),grey(0.99)))

plot.bathy(bathymetry,
           image = TRUE,
           land = TRUE,
           n=0,
           bpal = list(c(0, max(bathymetry), greys(100)),
                       c(min(bathymetry), 0, blues(100))))

# this is a 'bathy' object and you could plot it as is with the tools provided in marmap, but to keep things 'simple' I'm going to convert to sf. There is no direct method yet, so... don't judge me!
# convert from bathy to raster to 'sp' polygon to simple features
# bathypoly <- marmap::as.raster(bathymetry) %>%
    # rasterToPolygons() %>% st_as_sf
bathyras <- fortify.bathy(bathymetry)

bathyras$z[bathyras$z>0] <- NA

ggplot() +
    geom_raster(data=bathyras,aes(x=x,y=y,fill=z))+
    geom_sf(data=bb,fill="transparent",colour='black')

Canada <- getData('GADM', country="CAN", level=1) %>%
    st_as_sf() %>%
    filter(NAME_1=="Nova Scotia"|
               NAME_1=="Prince Edward Island"|
               NAME_1=="New Brunswick")
ggplot() +
    geom_sf(data=Canada,aes(fill=NAME_1))

x=0.2
ggplot() +
    geom_raster(data=bathyras,aes(x=x,y=y,fill=z))+
    geom_sf(data=bb,fill="transparent",colour='yellow',size=2)+
    geom_sf(data=Canada,fill='grey40')+
    coord_sf(xlim = c(lonmin-x,lonmax+x),
             ylim = c(latmin-x,latmax+x),
             expand = F)

Overlay your species occurrences over the base map

OBIS <- st_as_sf(OBIS,
                 coords = c("decimalLongitude", "decimalLatitude"),
                 crs="+proj=longlat +datum=WGS84",
                 remove=FALSE) %>%
    filter(!is.na(species))

    ggplot(OBIS) +
        geom_raster(data=bathyras,aes(x=x,y=y,fill=z))+
        geom_sf(data=bb,fill="transparent",colour='yellow',size=2)+
        geom_sf(data=Canada,fill='grey40')+
        geom_point(data=OBIS,aes(x=decimalLongitude,y=decimalLatitude))+
        facet_wrap(~phylum)+
        coord_sf(xlim = c(lonmin-x,lonmax+x),
                 ylim = c(latmin-x,latmax+x),
                 expand = F)

<<BACK